home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!windmill!charlie.brown
- Distribution: world
- Newsgroups: comp.lang.c
- From: charlie.brown@windmill.com (Charlie Brown)
- Date: Fri, 12 Jan 1996 11:10:00 -0600
- Organization: The Windmill Company BBS - 806-792-6116
- Subject: Cheap Temp. Sensor 1/2
- Message-ID: <59.26227.5782@windmill.com>
-
- /****
- Try this!!!
- Plug a $2 Radio Shack thermister into the joystick port and
- you've got a cheap temperature sensor. I attach these with
- speaker wire to monitor 4 snake cages but you don't need to
- do all that soldering just to play with it. The leads on the
- thermister have the right spacing. Just stick it in one of
- these positions: pins 2-3, 6-7, 10-11, or 13-14. Since it's
- a resistor you don't have to worry about getting it backwards.
- -------------------
- \ 1 2 3 4 5 6 7 8 /
- \ 9 0 1 2 3 4 5 /
- ---------------
- The following code will read the port but you'll have to convert
- that to the temperature. As the temperature goes up the number read
- from the port will go down. The graph of the temp vs what you get
- from the port is *almost* a straight line. I have more code that
- calibrates and graphs the temperature if anybody wants it let me
- know. I hate to clutter up the group with a lot of code nobody wants.
-
- Here's the code:
- ****/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <conio.h>
-
- int Joy_Port_Address = 0x201; // game port base address
- struct hack_bytes
- {
- unsigned char hack_hi;
- unsigned char hack_lo;
- };
- union hack
- {
- struct hack_bytes b;
- unsigned int w;
- };
- /************************************************************************
- * JOYSTICK_POSITION *
- *************************************************************************/
- int Joystick_Position(int which_one)
- {
- int counter;
- unsigned char mask;
- union hack hack1,hack2;
-
- mask = (unsigned char) pow(2.0,(double)which_one);
-
- _asm
- {
- MOV CX,2000
- MOV DX,Joy_Port_Address
-
- MOV AH,mask
-
- OUT DX,AL
- MOV AL, 0x34
- OUT 0x43,AL
- MOV AL,0
- OUT 0x40, AL
- OUT 0x40, AL
- OUT 0x43, AL
- IN AL,0x40
- MOV hack1.b.hack_hi,AL
- IN AL,0x40
- MOV hack1.b.hack_lo,AL
- }
-
- READ:
- _asm
- {
- IN AL,DX
- TEST AL,AH
- LOOPNZ READ
- MOV counter,CX
- IN AL,0x40
- MOV hack2.b.hack_hi,AL
- IN AL,0x40
- MOV hack2.b.hack_lo,AL
- MOV AL, 0x36
- OUT 0x43,AL
- MOV AL,0
- OUT 0x40, AL
- OUT 0x40, AL
- }
-
-
- if(counter == 0)
- return(0);
-
- if(hack2.w > hack1.w)
-
- (Continued to next message)
- ---
- * QMPro 1.01 41-4987 * BorgBurger: We do it our way. Your way is irrelevant.
-